Component({
  mixins: [],
  data: {
    that:this,
  },
  props: {},
  didMount() {
    this.setData({
       item:this.props.data,
       currIndex: this.props.data.startIndex - 1 || 0,
       endIndex: this.props.data.endIndex||this.props.data.allHang * this.props.data.allLie -1,
       oncetime: this.props.data.oncetime || 1,
       allHang: this.props.data.allHang,
      allLie: this.props.data.allLie,
      second:this.props.data.second,
      loop:this.props.data.loop || false,
      oncewidth:this.props.data.oncewidth,
      onceheight:this.props.data.onceheight,
      hang:0,
      lie:0,
      lastFrameTime:0,
      multigraph:this.props.data.multigraph
    },()=>{
      this.startPlay();
    })
  },
  didUpdate(){

  },
  didUnmount() {
      // abortAnimationFrame(this.requestID)
  },
      
    
  methods: {
  //初始化动画播放
 startPlay(){
        this.startTime = new Date().getTime();
        this.playStutas = 'play';
        this.play = true;
       this.animationLoop()
    },
    //帧动画
    animationLoop(){
        let { oncetime, endIndex, allLie,oncewidth,onceheight} = this.data;
        let currTime = new Date().getTime();
        let deltaTime = currTime - this.startTime;
        if (deltaTime > oncetime*1000) {  //毫秒播完
            if (this.second > 1 && !this.data.loop) {
                this.second -= 1;
                this.startTime = new Date().getTime();
            } else if (this.data.loop) {
                this.startTime = new Date().getTime()+300;
            } else {
                this.playStutas = 'pause';
                return
            }
        }
        if (this.playStutas == 'play') {
            let curr = Math.round(deltaTime/(oncetime * 1000) * endIndex)
             let hang=Math.floor(curr/allLie);
             let lie=curr % allLie;
              var sequenceanimation=my.createAnimation({
                transformOrigin:"top top",
                duration:0,
                timeFunction:"step-start",
                delay:0,
              });
              sequenceanimation.translate(`${-oncewidth*lie}rpx`,`${-onceheight*hang}rpx`).step({duration:0});
              this.setData({
                sequence:sequenceanimation.export()
              })  
               
        }
        this.requestID =doAnimationFrame(this.animationLoop.bind(this));
       
    },
  },
  
});

